class TextChatWnd extends eui.Component {

    private closeBtn:eui.Image;
    private contentBg1:egret.Sprite = new egret.Sprite();
    private contentBg2:egret.Sprite = new egret.Sprite();
    private GroupObj1:windowGroup;
    private GroupObj2:windowGroup;
    // private txobj:Array<any> = [
    //         {str:"啊~糟了！",soundCode:"Lspeak4",id:0},
    //         {str:"快点啊，等得我花都谢了！",soundCode:"Lspeak1",id:1},
    //         //{str:"和你合作真是太愉快了！",soundCode:"Lspeak2"},
    //         {str:"喂！你这么牛X你家人知道吗？",soundCode:"Lspeak3",id:2},            
    //         {str:"怎么又断线了，网络也太差了！",soundCode:"Lspeak5",id:3},
    //         //{str:"不胜利，吾宁死！",soundCode:"Lspeak6"},
    //         {str:"别吵啦，别吵啦，专心玩游戏吧！",soundCode:"Lspeak7",id:4}/*,
    //         {str:"不要走，决战到天亮！",soundCode:"Lspeak8"},
    //         {str:"土豪，我们做朋友吧！",soundCode:"Lspeak9"},*/];

    private txobj:Array<any> = [
        {str: '我出去叫人。', soundCode: 'wochuqu', id: 0},        
        {str: '别走，决战到天亮！', soundCode: 'biezou', id: 1},
        {str: '快点吧，时间就是金钱！', soundCode: 'kuaidianba', id: 2},
        {str: '牌好，心情就好！', soundCode: 'paihao', id: 3},
        {str: '输的裤衩都没了！', soundCode: 'shudekucha', id: 4},
        {str: '说多了都是泪，赢多了都是罪！', soundCode: 'shuoduole', id: 5},
        {str: '放炮不可怕，只要能自摸。', soundCode: 'fangpaobukepa', id: 6},
        {str: '命里有时终须胡，命里无时莫强贪。', soundCode: 'mingliyoushi', id: 7},
        {str: '我们的口号是不放炮！', soundCode: 'womendekouhao', id: 8},
        {str: '有时小胡也能起大作用！', soundCode: 'youshixiaohu', id: 9}
    ]

	public constructor() {
		super();
        this.addEventListener(eui.UIEvent.COMPLETE,this.onComplete,this);
		this.skinName = "src/Game/gameRoom/chat/TextChat.exml";	 
	}
	public onComplete():void{ 
       // console.log("表情界面加载完");
		this.removeEventListener(eui.UIEvent.COMPLETE,this.onComplete,this);
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.init,this);
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE,this.onRemove,this);
        var bqobj:Array<string> = [
        "a01","a02","a03",
        "a04","a05","a06",
        "a07","a08","a09"];
        for(var i:number=0;i<bqobj.length;i++){
            var tu:chatImageobjWnd = new chatImageobjWnd();
            tu.name = "face_"+bqobj[i];
            tu.setData("bq_"+bqobj[i]+"_png");
            tu.x = 110*(i%3);
            tu.y = Math.floor(i/3)*150;
            this.contentBg1.addChild(tu);
        }
        this.GroupObj1 = new windowGroup(340,455,this.contentBg1);
        this.GroupObj1.x = 40;
        this.GroupObj1.y = 112;
        this.addChild(this.GroupObj1);
            
        for(var i:number=0;i<this.txobj.length;i++){
            var tx:chatTextobjWnd = new chatTextobjWnd();
            tx.name = "chat_"+this.txobj[i].soundCode+"_"+this.txobj[i].id;
            tx.setData(this.txobj[i].str);
            tx.y = 90*i;
            this.contentBg2.addChild(tx);
        }

        this.GroupObj2 = new windowGroup(446,445,this.contentBg2);
        this.GroupObj2.x = 403;
        this.GroupObj2.y = 112;
        this.addChild(this.GroupObj2);
	}
    private init(){
       // console.log("表情界面初始化");
        this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.closeClcik,this);
        this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this);
    }
    private onClick(e:egret.TouchEvent){
       // alert("click:"+e.target.parent.name);
        if(e.target.parent.name.split("_")[0]=="face"){
            this.dispatchEventWith("close",false,e.target.parent.name);
        }
        if(e.target.parent.name.split("_")[0]=="chat"){
            this.dispatchEventWith("close",false,e.target.parent.name+"_"+this.txobj[Number(e.target.parent.name.split("_")[2])].str);
        }
    }
    private closeClcik(e:egret.TouchEvent){
        this.dispatchEventWith("close",false,"");
    }
    private onRemove(e:egret.Event){
        this.removeEventListener(egret.Event.REMOVED_FROM_STAGE,this.onRemove,this);
        this.closeBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.closeClcik,this);
        this.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this);
       // console.log("表情功能被清除");
    }
}